<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 冒充继承    
        //   浅拷贝 + 寄生继承  


        function Person(name,age) {
            this.name = name;
            this.age = age;

        }

        Person.prototype.sayHello = function () {
            console.log('Hello' + this.name);
        }

        const p = new Person('张三',19); // 父类的实例

        // 寄生 
        function Child(gender){
            this.gender = gender;
            Object.assign(this,p);// 浅拷贝一份父类的实例

        }
        // 直接上面的写法 继承不到父类的方法  
        Child.prototype = Person.prototype;
        const s = new Child('男');
        console.log(s);
        console.log(s.name);
        console.log(s.age);

        s.sayHello()
        


    </script>
</body>

</html>